package cn.passlink.www.Controller;

import cn.passlink.www.Utils.JsonUtils;
import cn.passlink.www.Utils.ReqDataCheck;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@Slf4j
@RequestMapping("/ai")
public class AiController {
    //上传问题
    @PostMapping("/answer")
    public Map<String, Object> answer(@RequestBody Map<String, Object> requestData) {

        String[] keys = {"question"};
        if (!ReqDataCheck.ReqDataCheckKeys(requestData, keys)) {
            log.error("question字段缺失");
            return JsonUtils.resultJson(403, "请求数据错误");

        }
        log.info("获取ai问题");
        String question = (String) requestData.getOrDefault("question", "");
        if (question.isEmpty()) {
            log.error("question字段为空");
            return JsonUtils.resultJson(403, "字符为空！！！");
        }
        Map<String, Object> res = new HashMap<>();
        log.info("回复---");
        res.put("answer", question);
        return JsonUtils.dataJson(200, res, "ok");

    }

}
